package g4p.newg4p;

import g4p_controls.G4P;
import g4p_controls.GButton;
import g4p_controls.GCScheme;
import g4p_controls.GEvent;
import g4p_controls.GWinApplet;
import g4p_controls.GWinData;
import g4p_controls.GWindow;
import processing.core.PApplet;

public class WindowsCloseTest extends PApplet {

	public void setup(){
		size(480, 320, JAVA2D);
		createGUI();
		// Place your setup code here

	}

	public void draw(){
		background(255);
		fill(0);
		if(G4P.isWindowOpen(window1))
			text("Window 1  >> OPEN", 140, 20);
		else
			text("Window 1  >> CLOSED", 140, 20);
			
		if(G4P.isWindowOpen(window2))
			text("Window 2  >> OPEN", 140, 70);
		else
			text("Window 2  >> CLOSED", 140, 70);
			
	}


	public void window1close(GWindow window){
		System.out.println(window.getTitle() + "  closing method called");
	}
	
	
	public void window2close(GWindow window){
		System.out.println(window.getTitle() + "  closing method called");
	}
	
	public void window3close(GWindow window){
		System.out.println(window.getTitle() + "  closing method called");	
	}
	
	
	public void button1_click1(GButton source, GEvent event) { //_CODE_:button1:957818:
		window1.forceClose();
	} //_CODE_:button1:957818:

	public void button2_click1(GButton source, GEvent event) { //_CODE_:button2:911405:
		window2.close();
	} //_CODE_:button2:911405:

	synchronized public void win_draw1(GWinApplet appc, GWinData data) { //_CODE_:window1:908312:
		appc.background(230);
	} //_CODE_:window1:908312:

	synchronized public void win_draw2(GWinApplet appc, GWinData data) { //_CODE_:window2:224284:
		appc.background(230);
	} //_CODE_:window2:224284:



	// Create all the GUI controls. 
	// autogenerated do not edit
	public void createGUI(){
		G4P.messagesEnabled(false);
		G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
		G4P.setCursor(ARROW);
		if(frame != null)
			frame.setTitle("Sketch Window");
		button1 = new GButton(this, 20, 20, 80, 30);
		button1.setText("Face text");
		button1.addEventHandler(this, "button1_click1");
		button2 = new GButton(this, 20, 70, 80, 30);
		button2.setText("Face text");
		button2.addEventHandler(this, "button2_click1");
		
		window1 = new GWindow(this, "Window 1", 600, 40, 240, 120, false, JAVA2D);
		window1.addDrawHandler(this, "win_draw1");
		window1.addOnCloseHandler(this, "window1close");
		
		window2 = new GWindow(this, "Window 2", 600, 240, 240, 120, false, JAVA2D);
		window2.addDrawHandler(this, "win_draw2");
		window2.setActionOnClose(G4P.CLOSE_WINDOW);
		window2.addOnCloseHandler(this, "window2close");
		
		window3 = new GWindow(this, "Window 3", 600, 440, 240, 120, false, JAVA2D);
		window3.addDrawHandler(this, "win_draw2");
		window3.setActionOnClose(G4P.EXIT_APP);
		window3.addOnCloseHandler(this, "window3close");
	}

	// Variable declarations 
	// autogenerated do not edit
	GButton button1; 
	GButton button2; 
	GWindow window1;
	GWindow window2;
	GWindow window3;

}
